home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / owldbf.zip / CREATTBL.CPP next >
C/C++ Source or Header  |  1992-11-24  |  3KB  |  86 lines

  1. //  Borland Paradox Engine 3.0 Database Framework program example
  2. //  Copyright (c) 1992 by Borland International   
  3. //  Modified DBF example...
  4. //  CREATTBL - provides an example showing how to create a table
  5. //             using the Database Framework.
  6. //
  7. //  This example uses the createTable member function of the
  8. //  BDatabase class to create a new table defined by the array
  9. //  of field descriptors fldArray.
  10. //
  11.  
  12. #include <iostream.h>
  13. #include <string.h>
  14.  
  15. // Paradox Engine 3.0 Header files.
  16.  
  17. #include <pxengine.h>
  18. #include <envdef.h>   // Environment definitions for Database Framework.
  19. #include <bengine.h>  // Header file for the BEngine class.
  20. #include <bdatabas.h> // Header file for the BDatabase class.
  21. #include <windows.h>
  22. // Specify the name of the table you want to create.
  23.  
  24. const char *tblName = "table1";
  25. void CreateTable( HWND& HWindow)
  26. {  // Fill in the FieldDesc structure for every field in the table.
  27.  
  28. // Call the BEngine constructor and initialize the engine to
  29. // single user or "PXInit()" mode.
  30.  
  31. BEngine Eng(pxWin);
  32.  if (Eng.lastError != PXSUCCESS)
  33.   MessageBox(HWindow, Eng.getErrorMessage(Eng.lastError),
  34.        "Engine error: ", MB_OK);
  35.   else
  36.   MessageBox(HWindow, tblName, "Engine OK", MB_OK);
  37. // Create and open the BDatabase instance DB with respect
  38. // to the BEngine instance Eng.
  39.  
  40. BDatabase DB(&Eng);
  41.  if (DB.lastError != PXSUCCESS)
  42.   MessageBox(HWindow, Eng.getErrorMessage(DB.lastError),
  43.        "Database error: ", MB_OK);
  44.   else
  45.   MessageBox(HWindow, tblName, "data base OK", MB_OK);
  46. // Array of field descriptors for the table, needed for the
  47. // createTable member function in the BDatabase class.
  48.  
  49. FieldDesc fldArray[3];
  50.  
  51. // Number of fields in the table.
  52.  
  53. const int numFields = sizeof(fldArray) / sizeof(fldArray[0]);
  54.  
  55.  
  56.   fldArray[0].fldNum = 1;
  57.   strcpy(fldArray[0].fldName, "Name");
  58.   fldArray[0].fldType = fldChar;  // Create an alphanumeric field.
  59.   fldArray[0].fldLen = 50;        // Specify the length of the field.
  60.  
  61.   fldArray[1].fldNum = 2;
  62.   strcpy(fldArray[1].fldName, "Address");
  63.   fldArray[1].fldType = fldChar;
  64.   fldArray[1].fldLen = 50;
  65.  
  66.   fldArray[2].fldNum = 3;
  67.   strcpy(fldArray[2].fldName, "Age");
  68.   fldArray[2].fldType = fldShort;  // Create a short field.
  69.  
  70.   // Create the table 'tblName' with the structure provided in the
  71.   // array of field descriptors fldArray.
  72.  
  73.   DB.createTable(tblName, numFields, fldArray);
  74.  
  75.   // Check to see if there was an error.
  76.  
  77.   if (DB.lastError != PXSUCCESS)
  78.   MessageBox(HWindow, Eng.getErrorMessage(DB.lastError),
  79.        "table create error: ", MB_OK);
  80.   else
  81.   MessageBox(HWindow, tblName, "table created successfully", MB_OK);
  82.  
  83.  // return DB.lastError;
  84.  
  85. }
  86.